// 仅示例
import request from '@/utils/request'
import {useAppStore} from "@/store/app";

const {UPDATE_UPLOAD} = useAppStore()


export function message() {
    return request({
        url: '/message',
        method: 'get'
    })
}

export function getOrder(id) {
    return request({
        url: `/orders/${id}`,
        method: 'get'
    })
}

export function wAnDaAi(data) {
    return request({
        url: `/biopsy/WAnDaAi`,
        method: 'post',
        data: data
    })
}


const post = function (url, data, config) {
    return new Promise((resolve, reject) => {
        request.post(url, data, config).then(res => {
            return resolve({...res})
        }).catch(error => {
            return reject(error)
        })
    })

}


export function uploadPhoto(data, fileObj) {
    return post(
        // "http://www.aikeji.top:5009/upload",  //演示环境
        // "https://h5.wdjky.com/jiankang/pathology-api/upload", //健康云
        "http://hz.nbpathcent.org:3000/pathology-api/upload", //宁波远程
        data,
        {
            headers: {"Content-Type": "multipart/form-data", repeatSubmit: false},
            timeout: 600000,
            onUploadProgress: (progressEvent) => {
                console.log(progressEvent)
                if (progressEvent.progress) {   //是否存在进度
                    fileObj.progress = Math.floor(progressEvent.loaded / progressEvent.total * 100)
                    fileObj.total = progressEvent.total
                    fileObj.loaded = progressEvent.loaded
                    if (fileObj.progress === 100) fileObj.isUploaded = true
                    UPDATE_UPLOAD(fileObj)
                }
            }
        });
}

export function GetInfo() {
    return new Promise((resolve, reject) => {
        request({
            url: '/getInfo',
            method: 'get'
        }).then((res) => {
            sessionStorage.setItem('permissions', JSON.stringify(res.permissions))
            sessionStorage.setItem('user', JSON.stringify(res.user))
            sessionStorage.setItem('roles', JSON.stringify(res.roles))
            const user = res.user;
            if (res.roles && res.roles.length > 0) {
                // 验证返回的roles是否是一个非空数组
            } else {
            }
            resolve(res);
        })
            .catch((error) => {
                reject(error);
            });
    });
}



